package com.cuntian.controller;

import com.cuntian.dto.LoginDTO;
import com.cuntian.dto.RegisterDTO;
import com.cuntian.result.Result;
import com.cuntian.result.ResultUtils;
import com.cuntian.service.IUserService;
import com.cuntian.vo.LoginVO;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class LoginController {

    private final IUserService userService;

    @PostMapping("/login")
    public Result<LoginVO> login(@Valid @RequestBody LoginDTO dto) {
        LoginVO login = userService.login(dto);
        return ResultUtils.success(login);
    }

    @PostMapping("/register")
    public Result<String> register(@Valid @RequestBody RegisterDTO dto) {
        userService.register(dto);
        return ResultUtils.success("注册成功");
    }

    @GetMapping("/logOut")
    public Result<String> logOut(){
        userService.logOut();
        return ResultUtils.success("退出成功");
    }

}
